package com.aaa.service.impl;

import com.aaa.dao.GoodsDao;
import com.aaa.dao.impl.GoodsDaoImpl;
import com.aaa.entity.Goods;
import com.aaa.service.GoodsService;
import com.aaa.util.BusinessException;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GoodsServiceImpl implements GoodsService {

    private GoodsDao goodsDao = new GoodsDaoImpl();

    @Override
    public int addGoods(Goods goods) {

        return goodsDao.addGoods(goods);
    }

    @Override
    public Map<String, Object> getConsumerGoodList(Integer pageNumber, Integer pageSize, String searchId, String searchName) throws Exception {
        if (pageNumber == null || pageNumber == 0) {
            throw new BusinessException("当前页数不能为空");
        }
        if (pageSize == null || pageSize == 0) {
            throw new BusinessException("每页条数不能为空");
        }
        pageNumber = (pageNumber - 1) * pageSize;
        List<Goods> list = goodsDao.consumerGoodList(pageNumber, pageSize, searchId, searchName);
        int count = goodsDao.getConsumerGoodListCount(searchId, searchName);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("count", count);
        return map;
    }

    @Override
    public int consumerGoods(Integer goodsId, Integer code) throws Exception {

        return goodsDao.consumerGoods(goodsId,code);
    }

    @Override
    public Map<String, Object> consumerGoodList(Integer pageNumber, Integer pageSize, String searchId, String searchName) throws BusinessException {
        if (pageNumber == null || pageNumber == 0) {
            throw new BusinessException("当前页数不能为空");
        }
        if (pageSize == null || pageSize == 0) {
            throw new BusinessException("每页条数不能为空");
        }
        pageNumber = (pageNumber - 1) * pageSize;
        List<Goods> list = goodsDao.getConsumerGoodsList(pageNumber, pageSize, searchId, searchName);
        int count = goodsDao.getConsumerGoodListCount(searchId, searchName);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("count", count);
        return map;
    }


}
